package com.gukun.springboot.tdengine.service.highvolume;

import com.gukun.springboot.tdengine.pojo.TagInfo;
import com.gukun.springboot.tdengine.domain.enums.TagType;

import java.util.ArrayList;
import java.util.List;

/**
 * className: DataConst
 * desc:
 * user: gukun
 * date: 2024/8/17 16:39
 */
public class DataUtil {
    public static final String DBNAME = "syncdb_gukun_test";
    public static final String JDBCURL = "jdbc:TAOS://127.0.0.1:6030/test?charset=UTF-8&timezone=UTC-8&user=root&password=taosdata";

    private static final String TAG_PRE = "tag";
    /**
     * 保存测点
     * 新建0-999 ： double
     * 1000~1999:float
     * 1999~2999:bool
     * 2999~3999:int
     */
    public static List<TagInfo> getTagInfos(int count) {
        int batch = count / 4;
        List<TagInfo> list = new ArrayList<>();
        for (long i = 0L; i < batch; i++) {
            TagInfo tagInfo = mockTagInfo(i, TAG_PRE, TagType.DOUBLE);
            list.add(tagInfo);
        }

        for (long i = batch; i < batch * 2; i++) {
            TagInfo tagInfo = mockTagInfo(i, TAG_PRE, TagType.FLOAT);
            list.add(tagInfo);
        }

        for (long i = batch * 2; i < batch * 3; i++) {
            TagInfo tagInfo = mockTagInfo(i, TAG_PRE, TagType.BOOL);
            list.add(tagInfo);
        }

        for (long i = batch * 3; i < count; i++) {
            TagInfo tagInfo = mockTagInfo(i, TAG_PRE, TagType.INT);
            list.add(tagInfo);
        }
        return list;
    }

    /**
     * 根据测点ID和前缀生成标准测点
     * @param tagId 测点ID，用于唯一标识测点
     * @param pre 前缀，用于构建测点名称
     * @param type 测点类型，定义了测点的类别
     * @return 返回构建的TagInfo对象，包含测点的详细信息
     */
    private static TagInfo mockTagInfo(Long tagId, String pre, TagType type) {
        TagInfo tagInfo = new TagInfo();
        tagInfo.setTagId(tagId);
        tagInfo.setTagName(pre + tagId);
        tagInfo.setPointNum(2);
        tagInfo.setTagType(type);

        return tagInfo;
    }
}
